import React, { Component } from 'react'
import { Button, DatePicker, Space } from 'antd'
import { NavLink, Route, Switch, Redirect } from 'react-router-dom'
import News from './news'
import Message from './Message'
import './index.scss'
import Login from './../../http/modules/login'
import MyPagination from '../../components/MyPagination'
export default class home extends Component {
    state = {
        url: '',
        page: {
            pageSize: 10,
            current: 5,
            total: 500
        }
    }
    clickSend = () => {
    }
    componentWillUnmount(){
        console.log("卸载了")
    }
    componentDidMount() {
        this.initImg();
        console.log("挂在之后")
    }
    initImg = () => {
        Login.code().then(res => {
            this.setState({
                url: res.image
            })
        }).catch(err => {
        })
    }
    imgClick = () => {
        this.initImg();
    }
    search = (current, pageSize) => {
        console.log(current, pageSize, "AAAAAAAAAAAAA")
        console.log(this.state.page)
    }
    myCurrent = (current, pageSize) => {
        console.log(current, pageSize)
        this.setState({
            page: {
                pageSize: pageSize,
                current: current,
                total: 100
            }
        },()=>{
            this.search(current,pageSize)
        })
    }
    render() {
        const { url, page } = this.state;
        return (
            <div className="home">
                <MyPagination {...page} myCurrent={this.myCurrent} />
                <div>
                    <Button type="primary" onClick={this.clickSend}>click send</Button>
                </div>
                <div onClick={this.imgClick}>
                    <img src={url} alt="" />
                </div>
                <div style={{ padding: '30px' }}>
                    <NavLink to="/home/news" className="active" activeClassName="homeActive">新闻</NavLink>
                    <NavLink to="/home/message" className="active" activeClassName="homeActive">新闻</NavLink>
                </div>
                <div>
                    <Switch>
                        <Route path="/home/news" component={News}></Route>
                        <Route path="/home/message" component={Message}></Route>
                        <Redirect to="/home/news"></Redirect>
                    </Switch>
                </div>
            </div>
        )
    }
}
